<template>
  <div class="fund-news" :style="{ ...border }">
    <div class="title fw-bold" :style="{ color: config.titleColor }">{{ config.title }}</div>
    <div class="panel" :style="{ backgroundColor: style.backgroundColor }">
      <div class="nav-bar" style="cursor: grab">
        <swiper :options="{ ...swiperOptions, spaceBetween: 0 }" class="fulled-h m-0">
          <swiper-slide v-for="(item, i) in config.groupList" :key="i" style="width: auto">
            <div class="nav-item pointer" :class="{ active: i === activeIndex }" @click="activePanel(i)">
              {{ item.name }}
            </div>
          </swiper-slide>
        </swiper>
      </div>
      <div class="layer">
        <div class="d-flex" style="padding-right: 32px">
          <swiper :options="swiperOptions" class="fulled-h" style="cursor: grab">
            <swiper-slide v-for="(item, i) in activeList" :key="i" style="width: auto">
              <div class="card" :style="{ backgroundImage: `url(${$staticRes(item.imgSrc)})` }">
                <div class="title t-white">
                  {{ item.title }}
                </div>
                <i class="icon-play"></i>
              </div>
            </swiper-slide>
          </swiper>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { swiper, swiperSlide } from 'vue-awesome-swiper';
  import 'swiper/dist/css/swiper.css';
  import borderMixin from '@/mixins/borderMixin';

  export default {
    components: { swiper, swiperSlide },
    mixins: [borderMixin],
    props: {
      widget: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      this.swiperOptions = {
        freeMode: true,
        slidesPerView: 'auto',
        roundLengths: true,
        resistanceRatio: 0,
        spaceBetween: 24,
        preventClicks: false,
        preventClicksPropagation: false
      };
      return {};
    },

    computed: {
      config() {
        return this.widget.config;
      },
      style() {
        return this.widget.style;
      },
      activeIndex() {
        return this.widget.data.activeIndex;
      },
      activeList() {
        return this.config.groupList[this.activeIndex].list;
      }
    },

    methods: {
      activePanel(i) {
        this.widget.data.activeIndex = i;
      }
    }
  };
</script>

<style lang="scss" scoped>
  .fund-news {
    font-size: 28px;

    > .title {
      min-height: 76px;
      font-size: 40px;
      line-height: 76px;
    }

    .panel {
      border-radius: 10px;
      padding: 32px 0 32px 32px;

      .nav-bar {
        display: flex;
        margin-bottom: 32px;
        padding-right: 32px;
        min-height: 48px;
        color: #999;

        ::v-deep .swiper-slide {
          .nav-item {
            flex-shrink: 0;
            border-bottom: 4px solid transparent;
            padding-bottom: 16px;

            &.active {
              border-color: #2842df;
              font-weight: bold;
              color: #2842df;
            }
          }
        }

        :not(:last-of-type) .nav-item {
          margin-right: 54px;
        }
      }

      .layer {
        .card {
          position: relative;
          flex-shrink: 0;
          border-radius: 10px;
          width: 300px;
          height: 204px;
          background-size: 100%;

          &:not(:last-of-type) {
            margin-right: 24px;
          }

          .title {
            position: absolute;
            top: 18px;
            left: 50%;
            width: 264px;
            font-size: 24px;
            line-height: 28px;
            transform: translateX(-50%);
          }

          .icon-play {
            @include bg('icons/icon-play.png');
            position: absolute;
            top: 90px;
            left: 50%;
            width: 64px;
            height: 64px;
            transform: translateX(-50%);
          }
        }
      }
    }
  }
</style>
